/*  
 * @(#) CacheFilter.java Create on 2012-5-8 下午12:25:03   
 *   
 * Copyright 2012 by xl.   
 */

package cn.com.common.interceptor;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * 清楚缓存
 * 
 * @author zhanghongliang
 * @date 2012-5-8
 */
@Controller
public class CacheInterceptor implements Interceptor {

	private Logger log = Logger.getLogger(ExceptionInterceptor.class);
	private static final long serialVersionUID = 1L;

	@Override
	public void destroy() {
		if (log.isDebugEnabled())
			log.debug("CacheInterceptor destroy...");
	}

	@Override
	public void init() {
		if (log.isDebugEnabled())
			log.debug("CacheInterceptor init...");
	}

	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		if (log.isDebugEnabled())
			log.debug("CacheInterceptor ...");
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Cache-Control", "no-store");
		response.setDateHeader("Expires", 0);
		return arg0.invoke();
	}
}
